/**
 * 通用接口请求
 */
import GetRequestActuator from './GetRequestActuator'
import PostRequestActuator from './PostRequestActuator'
import PostFormRequestActuator from './PostFormRequestActuator'
import DownLoadRequestActuator from './DownLoadRequestActuator'

import {getRequestConfig, setRequestConfig} from './config'

function createHanderWapper(RequestActuatorCls, url, data) {
  const instance = new RequestActuatorCls(getRequestConfig())
  const done = instance.done
  instance.done = function () {
    return done.call(instance, url, data)
  }
  return instance
}

export function get(url, data) {
  return createHanderWapper(GetRequestActuator, url, data)
}

export function post(url, data) {
  return createHanderWapper(PostRequestActuator, url, data)
}

export function postForm(url, data) {
  return createHanderWapper(PostFormRequestActuator, url, data)
}

export function download(url, data) {
  return createHanderWapper(DownLoadRequestActuator, url, data)
}

export {getRequestConfig, setRequestConfig}
